
import com.cognos.developer.schemas.bibus._3.BaseClass;
import com.cognos.developer.schemas.bibus._3.BiBusHeader;
import com.cognos.developer.schemas.bibus._3.CAM;
import com.cognos.developer.schemas.bibus._3.ContentManagerService_PortType;
import com.cognos.developer.schemas.bibus._3.ContentManagerService_ServiceLocator;
import com.cognos.developer.schemas.bibus._3.DataSourceConnection;
import com.cognos.developer.schemas.bibus._3.DateTimeProp;
import com.cognos.developer.schemas.bibus._3.Dispatcher_Type;
import com.cognos.developer.schemas.bibus._3.DisplayObject;
import com.cognos.developer.schemas.bibus._3.HdrSession;
import com.cognos.developer.schemas.bibus._3.PromptOption;
import com.cognos.developer.schemas.bibus._3.PropEnum;
import com.cognos.developer.schemas.bibus._3.QueryOptions;
import com.cognos.developer.schemas.bibus._3.SearchPathMultipleObject;
import com.cognos.developer.schemas.bibus._3.SearchPathSingleObject;
import com.cognos.developer.schemas.bibus._3.Sort;
import com.cognos.developer.schemas.bibus._3.StringProp;
import com.cognos.developer.schemas.bibus._3.UpdateOptions;
import com.cognos.developer.schemas.bibus._3.XmlEncodedXML;
import com.inforim.cognos.utils.BIBusHeaderHelper;
import com.inforim.util.DESUtil;

import java.io.File;
import java.net.ConnectException;
import java.net.URL;
import java.rmi.RemoteException;
import java.util.GregorianCalendar;
import org.apache.axis.client.Stub;
import org.apache.axis.message.SOAPHeaderElement;

public class CubeSwap
{
  private String m_endpoint;
  private ContentManagerService_PortType cmService = null;
  private ContentManagerService_ServiceLocator cmServiceLocator;
  private static String BIBUS_NS="http://developer.cognos.com/schemas/bibus/3/";
  public CubeSwap(String paramString)
  {
    this.m_endpoint = paramString;
    if ((this.m_endpoint == null) || (this.m_endpoint.equals(""))) {
      return;
    }
    try
    {
      this.cmServiceLocator = new ContentManagerService_ServiceLocator();

      this.cmService = this.cmServiceLocator.getcontentManagerService(new URL(this.m_endpoint));
    }
    catch (Exception localException)
    {
      localException.printStackTrace();
    }
  }

  public boolean loginAnonymous()
  {
    if (!(loginAnonymousEnabled()))
    {
      return false;
    }

    CAM localCAM = new CAM();
    localCAM.setAction("logon");

    HdrSession localHdrSession = new HdrSession();

    BiBusHeader localBiBusHeader = new BiBusHeader();
    localBiBusHeader.setCAM(localCAM);
    localBiBusHeader.setHdrSession(localHdrSession);

    ((Stub)this.cmService).setHeader("", "biBusHeader", localBiBusHeader);
    return true;
  }

  public boolean login(String paramString1, String paramString2, String paramString3)
  {
    try
    {
      StringBuffer localStringBuffer = new StringBuffer();
      localStringBuffer.append("<credential>");
      localStringBuffer.append("<namespace>" + paramString1 + "</namespace>");
      localStringBuffer.append("<password>" + paramString3 + "</password>");
      localStringBuffer.append("<username>" + paramString2 + "</username>");
      localStringBuffer.append("</credential>");
      XmlEncodedXML localXmlEncodedXML = new XmlEncodedXML();
      localXmlEncodedXML.set_value(localStringBuffer.toString());


      cmService.logon(localXmlEncodedXML,
				new SearchPathSingleObject[] {});
		// may get error of: CAF_VALIDATION_FAILURE
		SOAPHeaderElement soap = ((Stub) cmService).getResponseHeader(
				BIBUS_NS, "biBusHeader");
		((Stub) cmService).setHeader(soap);
    }
    catch (RemoteException localRemoteException)
    {
      return false;
    }
    return true;
  }

  public boolean loginAnonymousEnabled()
  {
    SearchPathMultipleObject localSearchPathMultipleObject = new SearchPathMultipleObject("~");
    try
    {
      this.cmService.query(localSearchPathMultipleObject, new PropEnum[0], new Sort[0], new QueryOptions());
    }
    catch (RemoteException localRemoteException)
    {
      return false;
    }
//    BiBusHeader localBiBusHeader = (BiBusHeader)((Stub)this.cmService).getHeaderObject("", "biBusHeader");
    BiBusHeader localBiBusHeader = BIBusHeaderHelper.getHeaderObject(((Stub)(this.cmService)).getResponseHeader(
			BIBUS_NS, "biBusHeader"));
    return (localBiBusHeader != null);
  }

  public String getNameSpaceIDforNameSpaceName(String paramString)
  {
    SearchPathMultipleObject localSearchPathMultipleObject = new SearchPathMultipleObject("/directory/namespace");

    String str1 = "";
    String str2 = "";
    try
    {
      BaseClass[] arrayOfBaseClass = this.cmService.query(localSearchPathMultipleObject, new PropEnum[0], new Sort[0], new QueryOptions());

      for (int i = 0; i < arrayOfBaseClass.length; ++i)
      {
        int j = arrayOfBaseClass[i].getSearchPath().getValue().indexOf("\"");
        int k = arrayOfBaseClass[i].getSearchPath().getValue().indexOf("\"", j);
        String str3 = arrayOfBaseClass[i].getSearchPath().getValue().substring(j, k);

        if (paramString.compareTo(arrayOfBaseClass[i].getDefaultName().getValue()) == 0)
        {
          return str3;
        }

      }

    }
    catch (RemoteException localRemoteException)
    {
      if ((localRemoteException.detail != null) && (ConnectException.class == localRemoteException.detail.getClass()))
      {
        System.out.println("Connection Failed.");
        return "";
      }

//      BiBusHeader localBiBusHeader = (BiBusHeader)((Stub)this.cmService).getHeaderObject("", "biBusHeader");
      BiBusHeader localBiBusHeader = BIBusHeaderHelper.getHeaderObject(((Stub)(this.cmService)).getResponseHeader(
  			BIBUS_NS, "biBusHeader"));
      DisplayObject[] arrayOfDisplayObject = localBiBusHeader.getCAM().getException().getPromptInfo().getDisplayObjects();
      str1 = "";
      str2 = "";
      for (int l = 0; l < arrayOfDisplayObject.length; ++l)
      {
        if (arrayOfDisplayObject[l].getName().equalsIgnoreCase("CAMNamespace"))
        {
          PromptOption[] arrayOfPromptOption = arrayOfDisplayObject[l].getPromptOptions();
          if (arrayOfPromptOption != null)
          {
            for (int i1 = 0; i1 < arrayOfPromptOption.length; ++i1)
            {
              if (paramString.compareTo(arrayOfPromptOption[i1].getValue()) == 0)
              {
                return arrayOfPromptOption[i1].getId();
              }

            }

          }

          if (arrayOfDisplayObject[l].getValue() == null)
            continue;
          str1 = arrayOfDisplayObject[l].getValue();
        }
        else {
          if (!(arrayOfDisplayObject[l].getName().equalsIgnoreCase("CAMNamespaceDisplayName")))
            continue;
          str2 = arrayOfDisplayObject[l].getValue();
        }

      }

      if (paramString.compareTo(str2) == 0)
      {
        return str1;
      }
    }
    return "";
  }

  public String checkNamespace(String paramString)
  {
    SearchPathMultipleObject localSearchPathMultipleObject = new SearchPathMultipleObject("/directory/namespace");

    String str1 = "";
    String str2 = "";
    try
    {
      BaseClass[] arrayOfBaseClass = this.cmService.query(localSearchPathMultipleObject, new PropEnum[0], new Sort[0], new QueryOptions());

      for (int i = 0; i < arrayOfBaseClass.length; ++i)
      {
        int j = arrayOfBaseClass[i].getSearchPath().getValue().indexOf("\"");
        int k = arrayOfBaseClass[i].getSearchPath().getValue().indexOf("\"", j);
        String str3 = arrayOfBaseClass[i].getSearchPath().getValue().substring(j, k);
        if (paramString.compareTo(str3) == 0)
        {
          return paramString;
        }

        if (paramString.compareTo(arrayOfBaseClass[i].getDefaultName().getValue()) == 0)
        {
          return str3;
        }

      }

    }
    catch (RemoteException localRemoteException)
    {
      if ((localRemoteException.detail != null) && (ConnectException.class == localRemoteException.detail.getClass()))
      {
        System.out.println("Connection Failed.");
        return paramString;
      }

//      BiBusHeader localBiBusHeader = (BiBusHeader)((Stub)this.cmService).getHeaderObject("", "biBusHeader");
      BiBusHeader localBiBusHeader = BIBusHeaderHelper.getHeaderObject(((Stub)(this.cmService)).getResponseHeader(
  			BIBUS_NS, "biBusHeader"));
      DisplayObject[] arrayOfDisplayObject = localBiBusHeader.getCAM().getException().getPromptInfo().getDisplayObjects();
      str1 = "";
      str2 = "";
      for (int l = 0; l < arrayOfDisplayObject.length; ++l)
      {
        if (arrayOfDisplayObject[l].getName().equalsIgnoreCase("CAMNamespace"))
        {
          PromptOption[] arrayOfPromptOption = arrayOfDisplayObject[l].getPromptOptions();
          if (arrayOfPromptOption != null)
          {
            for (int i1 = 0; i1 < arrayOfPromptOption.length; ++i1)
            {
              if (paramString.compareTo(arrayOfPromptOption[i1].getId()) == 0)
              {
                return paramString;
              }

              if (paramString.compareTo(arrayOfPromptOption[i1].getValue()) == 0)
              {
                return arrayOfPromptOption[i1].getId();
              }

            }

          }

          if (arrayOfDisplayObject[l].getValue() == null)
            continue;
          str1 = arrayOfDisplayObject[l].getValue();
        }
        else {
          if (!(arrayOfDisplayObject[l].getName().equalsIgnoreCase("CAMNamespaceDisplayName")))
            continue;
          str2 = arrayOfDisplayObject[l].getValue();
        }
      }

      if (paramString.compareTo(str1) == 0)
      {
        return paramString;
      }

      if (paramString.compareTo(str2) == 0)
      {
        paramString = str1;
      }

    }

    return paramString;
  }

  public void logoff()
  {
    try
    {
      this.cmService.logoff();
    }
    catch (RemoteException localRemoteException)
    {
      localRemoteException.printStackTrace();
    }
  }

  public BaseClass[] getDispatcher(String paramString)
  {
    PropEnum[] arrayOfPropEnum = { PropEnum.defaultName, PropEnum.searchPath };
    SearchPathMultipleObject localSearchPathMultipleObject = new SearchPathMultipleObject();
    localSearchPathMultipleObject.set_value("//*[@name='" + paramString + "']");
    try
    {
      BaseClass[] arrayOfBaseClass = this.cmService.query(localSearchPathMultipleObject, arrayOfPropEnum, new Sort[0], new QueryOptions());

      return arrayOfBaseClass;
    }
    catch (Exception localException) {
    	localException.printStackTrace();
    }
    return null;
  }

  public BaseClass[] getDataSource(String paramString)
  {
    SearchPathMultipleObject localSearchPathMultipleObject = new SearchPathMultipleObject();
    localSearchPathMultipleObject.set_value("//dataSource/dataSourceConnection[@name='" + paramString + "']");

    PropEnum[] arrayOfPropEnum = { PropEnum.defaultName, PropEnum.searchPath, PropEnum.connectionString };
    try
    {
      BaseClass[] arrayOfBaseClass = this.cmService.query(localSearchPathMultipleObject, arrayOfPropEnum, new Sort[0], new QueryOptions());

      return arrayOfBaseClass;
    }
    catch (Exception localException) {
    }
    return null;
  }

  public BaseClass[] updateDataConnectionString(BaseClass[] paramArrayOfBaseClass, String paramString)
  {
    String str1 = ((DataSourceConnection)paramArrayOfBaseClass[0]).getConnectionString().getValue();

    int i = str1.indexOf("WIN_PATH=") + 9;
    int j = str1.indexOf(";", i);
    int k = str1.indexOf("UNIX_PATH=") + 10;
    int l = str1.indexOf(";", k);

    if (j < 0)
    {
      j = str1.length();
    }
    if (l < 0)
    {
      l = str1.length();
    }

    String str2 = str1.substring(0, i);
    String str3 = str1.substring(i, j);
    String str4 = str1.substring(j, k);
    String str5 = str1.substring(k, l);
    String str6 = str1.substring(l);

    String str7 = str2;

    if (str5.length() > 0)
    {
      str7 = str7 + str3 + str4 + paramString + str6;
    }
    else
    {
      str7 = str7 + paramString + str4 + str5 + str6;
    }

    StringProp localStringProp = new StringProp();
    localStringProp.setValue(str7);

    ((DataSourceConnection)paramArrayOfBaseClass[0]).setConnectionString(localStringProp);
    try
    {
      return this.cmService.update(paramArrayOfBaseClass, new UpdateOptions());
    }
    catch (RemoteException localRemoteException)
    {
      localRemoteException.printStackTrace(); }
    return null;
  }

  public BaseClass[] updateDataConnectionString(BaseClass[] paramArrayOfBaseClass, String paramString1, boolean paramBoolean1, String paramString2, boolean paramBoolean2)
  {
    String str1 = ((DataSourceConnection)paramArrayOfBaseClass[0]).getConnectionString().getValue();

    int i = str1.indexOf("WIN_PATH=") + 9;
    int j = str1.indexOf(";", i);
    int k = str1.indexOf("UNIX_PATH=") + 10;
    int l = str1.indexOf(";", k);

    if (j < 0)
    {
      j = str1.length();
    }
    if (l < 0)
    {
      l = str1.length();
    }

    String str2 = str1.substring(0, i);
    String str3 = str1.substring(i, j);
    String str4 = str1.substring(j, k);
    String str5 = str1.substring(k, l);
    String str6 = str1.substring(l);

    String str7 = str2;
    if (paramBoolean1)
    {
      str7 = str7 + paramString1;
    }
    else
    {
      str7 = str7 + str3;
    }
    str7 = str7 + str4;
    if (paramBoolean2)
    {
      str7 = str7 + paramString2;
    }
    else
    {
      str7 = str7 + str5;
    }
    str7 = str7 + str6;

    StringProp localStringProp = new StringProp();
    localStringProp.setValue(str7);

    ((DataSourceConnection)paramArrayOfBaseClass[0]).setConnectionString(localStringProp);
    try
    {
      return this.cmService.update(paramArrayOfBaseClass, new UpdateOptions());
    }
    catch (RemoteException localRemoteException)
    {
      localRemoteException.printStackTrace(); }
    return null;
  }

  public BaseClass[] fireCubeSwap(Dispatcher_Type paramDispatcher_Type)
  {
    try
    {
      DateTimeProp localDateTimeProp = new DateTimeProp();

      GregorianCalendar localGregorianCalendar = new GregorianCalendar();
      localDateTimeProp.setValue(localGregorianCalendar);

      paramDispatcher_Type.setBrsDataSourceChange(localDateTimeProp);
      paramDispatcher_Type.setRsDataSourceChange(localDateTimeProp);

      return this.cmService.update(new BaseClass[] { paramDispatcher_Type }, null);
    }
    catch (RemoteException localRemoteException)
    {
      localRemoteException.printStackTrace(); }
    return null;
  }

  public String xmlEncodeHelper(String paramString)
  {
    StringBuffer localStringBuffer = new StringBuffer(paramString.length());

    for (int i = 0; i < paramString.length(); ++i)
    {
      switch (paramString.charAt(i))
      {
      case '&':
        localStringBuffer.append("&amp;");
        break;
      case '<':
        localStringBuffer.append("&lt;");
        break;
      case '>':
        localStringBuffer.append("&gt;");
        break;
      case '\'':
        localStringBuffer.append("&apos;");
        break;
      case '"':
        localStringBuffer.append("&quot;");
        break;
      default:
        localStringBuffer.append(paramString.charAt(i));
      }

    }

    return localStringBuffer.toString();
  }

  public static void usage()
  {
    System.out.println("");
    System.out.println("");
    System.out.println("CubeSwap 2.0 Command Line Options:");
    System.out.println("");
    System.out.println("     -anonymous");
    System.out.println("            flag to indicate that cubeswap should connect");
    System.out.println("            to the Cognos server using anonymous access");
    System.out.println("            NOTE: If this flag is used and login information ");
    System.out.println("            is also provided, the login information will be ignored");
    System.out.println("     -datasource=<value>");
    System.out.println("            name of the Data Source that will be updated");
    System.out.println("     -dispatchername=<value>");
    System.out.println("            name of dispatcher with services that");
    System.out.println("            use the cube being updated");
    System.out.println("     -help");
    System.out.println("            prints this help message and exits");
    System.out.println("     -namespaceid=<value>");
    System.out.println("            namespaceid for authenticating the specified user");
    System.out.println("     -namespacename=<value>");
    System.out.println("            namespacename for authenticating the specified user");
    System.out.println("            NOTE: if both namespaceid and namespacename are provided,");
    System.out.println("            the value specified for namespaceid will be used");
    System.out.println("     -oldhelp");
    System.out.println("            prints the help message from the 1.0 version of cubeswap");
    System.out.println("     -password=<value>");
    System.out.println("            password for the given user");
    System.out.println("     -unixcube=<value>");
    System.out.println("            the fully qualified unix name and path for the new cube");
    System.out.println("     -url=<value>");
    System.out.println("            URL for the Cognos Server");
    System.out.println("     -username=<value>");
    System.out.println("            username, valid within the namespace, for use");
    System.out.println("            connecting to the Cognos Server");
    System.out.println("     -version");
    System.out.println("            prints the version information for the cubeswap utility");
    System.out.println("     -windowscube=<value>");
    System.out.println("            the fully qualified windows name and path for the new cube");
    System.out.println("");
    System.out.println("Examples:");
    System.out.println("");
    System.out.println("");
    System.out.println("  cubeswap.bat -dispatchername=\"http://<hostname>:9300\" -datasource=\"great_outdoors_company\" -url=\"http://<hostname>:9300/p2pd/servlet/dispatch\" -windowscube=\"<drive>:\\<path>\\<cubename.mdc>\" ");
    System.out.println("  cubeswap.bat -dispatchername=\"http://<hostname>:9300\" -datasource=\"great_outdoors_company\" -url=\"http://<hostname>:9300/p2pd/servlet/dispatch\" -username=<user> -password=<password> -namespaceid=<namespace> -unixcube=\"/<path>/<cubename.mdc>\" ");
    System.out.println("");
    System.out.println("  Exit Codes:");
    System.out.println("             0 - Success");
    System.out.println("            -1 - Invalid command line arguments");
    System.out.println("            -2 - Login Failure");
    System.out.println("            -3 - Operation Failed");
  }

  public static void oldUsage()
  {
    System.out.println("");
    System.out.println("");
    System.out.println("Command Line Parameters:");
    System.out.println("");
    System.out.println("<URL> <dispatcherName> <dataSource> <newCube> [ <userName> <password> <nameSpace> ]");

    System.out.println("");
    System.out.println("  Required arguments:");
    System.out.println("");
    System.out.println("          URL - Cognos ReportNet Server URL");
    System.out.println("\t\t\teg. \"http://<hostname>:9300/p2pd/servlet/dispatch\"");
    System.out.println("  dispatcherName - name of dispatcher with services using the cube that will be updated");

    System.out.println("            eg. \"http://<hostname>:9300\"");
    System.out.println("      dataSource - name of the Data Source that will be updated with a new cube");

    System.out.println("            eg. \"Go Data Warehouse\"");
    System.out.println("         newCube - the fully qualified name and path for the new cube");
    System.out.println("             eg. \"<path>/<cubename.mdc>\"");
    System.out.println("");
    System.out.println("  Optional arguments: for use with secured namespace (Anonymous disabled)");

    System.out.println("");
    System.out.println("     userName - username, valid within the namespace, to run the utility");

    System.out.println("     password - password for the given user");
    System.out.println("    nameSpace - namespace for the desired user");
    System.out.println("");
    System.out.println("  Exit Code:     0 - Success");
    System.out.println("                -1 - Invalid command line arguments");
    System.out.println("                -2 - Login Failure");
    System.out.println("                -3 - Operation Failed");
  }

  public static void main(String[] paramArrayOfString)
  {
    Object paramValue;
    Object paramKey;
    int i = 1;
    int j = 0;
    boolean bool1 = false;
    int k = 1;

    String str1 = "";
    Object nameSpaceName = "";
    Object nameSpaceId = "";
    Object password = "";
    Object username = "";
    Object dispatcherName = "";
    Object dataSource = "";
    String str2 = "";
    Object windowsCube = "";
    boolean bool2 = false;
    Object unixCube = "";
    boolean bool3 = false;
    Object cogUrl = "";

    if ((paramArrayOfString.length > 0) && (paramArrayOfString[0].startsWith("-")))
    {
      for (int l = 0; l < paramArrayOfString.length; ++l)
      {
        int i1 = paramArrayOfString[l].indexOf("=");
        paramValue = "";
        if (i1 <= 0)
        {
          i1 = paramArrayOfString[l].length();
        }
        else
        {
          paramValue = paramArrayOfString[l].substring(i1 + 1, paramArrayOfString[l].length());
        }
        paramKey = paramArrayOfString[l].substring(0, i1).toUpperCase();

        if (((String)paramKey).compareTo("-URL") == 0)
        {
          cogUrl = paramValue;
        }
        else if (((String)paramKey).compareTo("-DISPATCHERNAME") == 0)
        {
          dispatcherName = paramValue;
        }
        else if (((String)paramKey).compareTo("-DATASOURCE") == 0)
        {
          dataSource = paramValue;
        } else {
          if (((String)paramKey).compareTo("-WINDOWSCUBE") == 0)
          {
            windowsCube = paramValue;
            File localFile = new File((String)paramValue);
            if (localFile.exists())
            {
              bool2 = true; continue;
            }

            System.out.println("Error: new cube file " + ((String)paramValue) + " doesn't exist.");
            System.out.println("Please check the new cube file to make sure the file name and location are correct.");
            return;
          }

          if (((String)paramKey).compareTo("-UNIXCUBE") == 0)
          {
            unixCube = paramValue;
            bool3 = true;
          }
          else if (((String)paramKey).compareTo("-USERNAME") == 0)
          {
            username = paramValue;
          }
          else if (((String)paramKey).compareTo("-PASSWORD") == 0)
          {
            password = paramValue;
          }
          else if (((String)paramKey).compareTo("-NAMESPACENAME") == 0)
          {
        	  nameSpaceName = paramValue;
          }
          else if (((String)paramKey).compareTo("-NAMESPACEID") == 0)
          {
            nameSpaceId = paramValue;
          }
          else if (((String)paramKey).compareTo("-ANONYMOUS") == 0)
          {
            k = 0;
          }
          else if ((((String)paramKey).compareTo("-HELP") == 0) || (((String)paramKey).compareTo("-H") == 0))
          {
            usage();
            System.exit(0);
          }
          else if (((String)paramKey).compareTo("-OLDHELP") == 0)
          {
            oldUsage();
            System.exit(0);
          }
          else if (((String)paramKey).compareTo("-VERSION") == 0)
          {
            System.out.println("Cubeswap 2.0");
            System.exit(0);
          }
          else
          {
            usage();
            System.exit(-1);
          }

        }

      }

      if ((((String)dataSource).compareTo("") == 0) || (((String)dispatcherName).compareTo("") == 0) || (((String)cogUrl).compareTo("") == 0) || ((k != 0) && (((((String)username).compareTo("") == 0) || (((String)password).compareTo("") == 0) || ((((String)nameSpaceId).compareTo("") == 0) && (((String)nameSpaceName).compareTo("") == 0))))))
      {
        usage();
        System.exit(-1);
      }

      j = 1;
    }
    else
    {
      i = 0;
      if ((paramArrayOfString.length != 7) && (paramArrayOfString.length != 4))
      {
        usage();
        System.exit(-1);
      }

      cogUrl = paramArrayOfString[0];
      dispatcherName = paramArrayOfString[1];
      dataSource = paramArrayOfString[2];
      str2 = paramArrayOfString[3];
      if (!(new File(str2).exists()))
      {
        System.out.println("Error: new cube file " + str2 + " doesn't exist.");
        System.out.println("Please check the new cube file to make sure the file name and location are correct.");
        return;
      }
      if (paramArrayOfString.length == 7)
      {
        username = paramArrayOfString[4];
        password = paramArrayOfString[5];
        str1 = paramArrayOfString[6];
      }
      else
      {
        k = 0;
      }

      j = 1;
    }

    CubeSwap localCubeSwap = null;
    if (j != 0)
    {
      localCubeSwap = new CubeSwap((String)cogUrl);
    }
    else
    {
      usage();
      System.exit(-1);
    }
    //解密密码
    try {
		password = (new DESUtil()).decrypt(password.toString()) ;
	} catch (Exception e) {
		// TODO Auto-generated catch block
		System.out.println("password decrypt error!");
		System.exit(-2);
	}
    if (i != 0)
    {
      if (k != 0)
      {
        if (((String)nameSpaceId).compareTo("") == 0)
        {
          nameSpaceId = localCubeSwap.getNameSpaceIDforNameSpaceName((String)nameSpaceName);
        }

        if (((String)nameSpaceId).compareTo("") == 0);
//        System.out.println(localCubeSwap.loginAnonymousEnabled());
        bool1 = localCubeSwap.login((String)nameSpaceId, (String)username, (String)password);
      }
      else
      {
        bool1 = localCubeSwap.loginAnonymous();
      }

    }
    else
    {
      str1 = localCubeSwap.checkNamespace(str1);
      if (k != 0)
      {
        bool1 = localCubeSwap.login(str1, (String)username, (String)password);
      }
      else
      {
        bool1 = localCubeSwap.loginAnonymous();
      }
    }

    if (bool1)
    {
      BaseClass[] arrayOfBaseClass = localCubeSwap.getDispatcher((String)dispatcherName);
      paramValue = localCubeSwap.getDataSource((String)dataSource);

      if ((arrayOfBaseClass != null) && (arrayOfBaseClass.length > 0))
      {
        paramKey = localCubeSwap.fireCubeSwap((Dispatcher_Type)arrayOfBaseClass[0]);

        if ((paramKey != null) && (((BaseClass[])paramKey).length > 0))
        {
          System.out.println("DataSourceChange properties for dispatcher: '" + ((String)dispatcherName) + "' updated successfully");
        }
      }

      if ((paramValue != null) && (((BaseClass[])paramValue).length > 0))
      {
        paramKey = null;

        if (i != 0)
        {
          paramKey = localCubeSwap.updateDataConnectionString((BaseClass[])paramValue, (String)windowsCube, bool2, (String)unixCube, bool3);
        }
        else
        {
          paramKey = localCubeSwap.updateDataConnectionString((BaseClass[])paramValue, str2);
        }

        if ((paramKey != null) && (((BaseClass[])paramKey).length > 0))
        {
          System.out.println("DataConnection String for dataSource: '" + ((String)dataSource) + "' updated successfully");

          System.exit(0);
        }

      }

      System.out.println("CubeSwap failed for  " + ((String)dispatcherName));
      System.exit(-3);
    }
    else
    {
      System.out.println("");
      System.out.println("Error: Login Failure - please try again.");
      System.exit(-2);
    }
  }
}